package com.tiancheng.trade.order.controller.admin;

import com.tiancheng.trade.commom.core.data.PageInfo;
import com.tiancheng.trade.commom.core.data.Result;
import com.tiancheng.trade.commom.core.utils.JsonUtil;
import com.tiancheng.trade.order.service.RefundOrdersDetailService;
import com.tiancheng.trade.order.vo.admin.QueryRefundVO;
import com.tiancheng.trade.order.vo.admin.QueryTotalRefundVO;
import com.tiancheng.trade.order.vo.admin.res.RefundDetailResVO;
import com.tiancheng.trade.order.vo.admin.res.RefundResVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 退款管理端接口
 *
 * @author kellen
 * @date 2024/3/27
 */
@RestController
@RequestMapping("/admin/order/refund")
@Slf4j
public class RefundAdminController {

	@Resource
	private RefundOrdersDetailService refundOrdersDetailService;

	/**
	 * 功能描述: 退款订单查询
	 *
	 * @param:
	 * @return:
	 * @auther: LiuDong
	 * @date: 13:38 2024/4/2
	 */
	@GetMapping("/findRefundList")
	public Result findRefundList(QueryRefundVO queryRefundVO) {
		log.info("退款订单查询 查询参数：{}", JsonUtil.toJsonString(queryRefundVO));
		PageInfo<RefundResVO> refunds = refundOrdersDetailService.queryRefundList(queryRefundVO);
		log.info("退款订单查询 返回结果：{}", JsonUtil.toJsonString(refunds));
		return Result.success(refunds);
	}

	/**
	 * 功能描述: 退款订单详情查询
	 *
	 * @param:
	 * @return:
	 * @auther: LiuDong
	 * @date: 13:38 2024/4/2
	 */
	@GetMapping("/{refundId}")
	public Result findRefundByRefundId(@PathVariable String refundId) {
		log.info("退款订单详情查询 查询参数 refundId：{}", refundId);
		RefundDetailResVO refund = refundOrdersDetailService.queryRefundOrderByRefundId(refundId);
		log.info("退款订单详情查询 返回结果：{}", JsonUtil.toJsonString(refund));
		return Result.success(refund);
	}

	/**
	 * 查询退款的总金额和数量
	 * @param queryTotalRefundVO
	 * @return
	 */
	@GetMapping(value = "/queryTotal")
	public Result queryTotal(QueryTotalRefundVO queryTotalRefundVO) {
		return Result.success(refundOrdersDetailService.queryTotal(queryTotalRefundVO));
	}
}
